export const contract_code = `
  // SPDX-License-Identifier: MIT
  pragma solidity ^0.8.17;
  contract TodoList {
    struct Todo {
      string text;
      bool completed;
    }
    string public  name = "TODO-LF";
    uint256 public total;
    Todo[] public todos;

    function create(string calldata _text) external {
      todos.push(Todo({
        text: _text,
        completed: false
      }));
      total++;
    }

    function updateText(uint _index, string calldata _text) external {
      require(_index < todos.length, "undefind");
      todos[_index].text = _text;
    }

    function get(uint _index) external view returns(string memory, bool)  {
      require(_index < todos.length, "not todo");  
      Todo storage todo = todos[_index];
        return (todo.text, todo.completed);
    }

    function completed(uint _index) external  {
      require(_index < todos.length, "undefind");
      require(todos[_index].completed = true, "have completed");
      todos[_index].completed = true;
      total--;
    }
  }
`

export const contract_address = `0xcD1D331CB95dE46b3B72B55Ce73DAF7b8f7c2505`

export const contract_abi = [
  'function completed(uint256 _index)',
  'function create(string _text)',
  'function get(uint256 _index) view returns (string, bool)',
  'function name() view returns (string)',
  'function todos(uint256) view returns (string text, bool completed)',
  'function total() view returns (uint256)',
  'function updateText(uint256 _index, string _text)',
]

export const contract_full_abi = [
  {
    inputs: [
      {
        internalType: 'uint256',
        name: '_index',
        type: 'uint256',
      },
    ],
    name: 'completed',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    inputs: [
      {
        internalType: 'string',
        name: '_text',
        type: 'string',
      },
    ],
    name: 'create',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    inputs: [
      {
        internalType: 'uint256',
        name: '_index',
        type: 'uint256',
      },
    ],
    name: 'get',
    outputs: [
      {
        internalType: 'string',
        name: '',
        type: 'string',
      },
      {
        internalType: 'bool',
        name: '',
        type: 'bool',
      },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'name',
    outputs: [
      {
        internalType: 'string',
        name: '',
        type: 'string',
      },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      {
        internalType: 'uint256',
        name: '',
        type: 'uint256',
      },
    ],
    name: 'todos',
    outputs: [
      {
        internalType: 'string',
        name: 'text',
        type: 'string',
      },
      {
        internalType: 'bool',
        name: 'completed',
        type: 'bool',
      },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'total',
    outputs: [
      {
        internalType: 'uint256',
        name: '',
        type: 'uint256',
      },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      {
        internalType: 'uint256',
        name: '_index',
        type: 'uint256',
      },
      {
        internalType: 'string',
        name: '_text',
        type: 'string',
      },
    ],
    name: 'updateText',
    outputs: [],
    stateMutability: 'nonpayable',
    type: 'function',
  },
]
